#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "stackfun.h"
stackele *creatstack(void)
{
	int len;
	printf(">>plz input max \n");
	printf(">> ");
	scanf("%d",&len);
	stackele *H=(stackele *)malloc(sizeof(stackele));
	H->data=(mydata *)malloc(len*sizeof(mydata));
	H->max=len;
	H->flag=-1;

	return H;
}

int stackin(stackele *H)
{
	char inputname[32];
	int inputage;

	if(H->flag<(H->max-1))
	{
		printf(">>plz input name \n");
		printf(">> ");
		scanf("%s",inputname);

		printf(">>plz input age \n");
		printf(">> ");
		scanf("%d",&inputage);

		H->flag++;
		H->data[H->flag].age=inputage;
		strcpy(H->data[H->flag].name,inputname);

		return 0;
	}
	else
	{
		printf("stack is full!\n");
		return -1;
	}
}

int stackout(stackele *H)
{
	if(H->flag==-1)
	{
		printf("stack is empty \n");
		return -1;
	}
	else
	{
		memset(H->data[H->flag].name,0,sizeof(H->data[H->flag].name));
		H->data[H->flag].age=0;
		H->flag--;
	}
	return 0;
}

int stackshow(stackele *H)
{
	int i=0;
	if(H->flag!=-1)
	{
		for(i=0;i<=(H->flag);i++)
		{
			printf("<%d>: %s,%d\n",i,H->data[i].name,H->data[i].age);
		}
		return 0;
	}
	else
	{
		printf("stack is empty\n");
		return -1;
	}
	
}
